<?php

namespace App\Http\Controllers\App;

use Illuminate\Http\Request;
use App\Models\Report;

class ReportController extends BaseController
{
    
    /**
     * 获得报表列表
     * @return [type] [description]
     */
    public function reportList(Request $request) {

        $time = $request->input('time');//时间

        if ($time != null) {
            $result = Report::where('audit_date', $time)->first();
        } else {
            $result = Report::orderBy('audit_date', 'desc')->paginate($this->pageSize);
        }

        return self::json($result);
    }


    /**
     * 获得报表详情
     * @return [type] [description]
     */
    public function getInfoList(Request $request) {

        $time = $request->input('time');//时间

        $rebate = new RebateOrder();

        $result = $rebate->leftjoin('wd_user', 'wd_rebate_order.user_id', '=', 'wd_user.id')
        ->where('wd_rebate_order.created_at', $time)
        ->paginate($this->pageSize);

        return self::json($result);
    }


    /**
     * 状态改变
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function changeStatus(Request $request) {

        $id     = $request->input('id');//id

        $status = $request->input('status');//1 未审 2 已审 3 完成
        
        if ($id == 0) return self::error('id有误');

        $report = Report::find($id);

        if(empty($report)) return self::error('id有误');
        
        $report->status = $status;

        $result = $report->save();

        return ($result == true) ? self::success('更改成功') : self::error('更改失败');
    }
}